import 'package:flutter/material.dart';

class SimpleMenuItem extends StatelessWidget {

  final Widget icon;
  final String title;

  const SimpleMenuItem(
      {Key? key,
        required this.icon,
        required this.title
      }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      child: Row(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Padding(
            padding: EdgeInsets.only(right: 8),
            child: icon,
          ),
          Text(
            title,
            style: TextStyle(
              color: Colors.black87,
            ),
          ),
        ],
      ),
    );
  }
}

class SwitchMenuItem extends StatefulWidget {

  final String title;
  final VoidCallback? onChangeCallback;
  bool state;

  SwitchMenuItem(
      {Key? key,
        required this.title,
        this.state = false,
        this.onChangeCallback,
      }) : super(key: key);

  @override
  State<StatefulWidget> createState() => _SwitchMenuItemState();
}

class _SwitchMenuItemState extends State<SwitchMenuItem> {
  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      child: Row(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Padding(
            padding: EdgeInsets.only(right: 8),
            child: Switch(
              value: widget.state,//当前状态
              onChanged:(value) => setState(() {
                widget.onChangeCallback?.call();
                widget.state = value;
              }),
            ),
          ),
          Text(
            widget.title,
            style: TextStyle(
              color: Colors.black87,
            ),
          ),
        ],
      ),
    );
  }
}